<?php 

class App_carriers extends MY_Library {

function __construct()
{
	parent::__construct();

	$this->PACKAGE->routing->load->library('carriers/carriers');
}


public function enable_carrier($carrier_id)
{
	// load required models
	$this->APPLICATION->load->model('app_mod_carriers');
	
	// other actions
	
	// change carrier status in database
	$result = $this->APPLICATION->app_mod_carriers->change_status($carrier_id,'1');
	
	return $result;
}

public function disable_carrier($carrier_id)
{
	// load required models
	$this->APPLICATION->load->model('app_mod_carriers');
	
	// other actions
	
	// change carrier status in database
	$result = $this->APPLICATION->app_mod_carriers->change_status($carrier_id,'0');
	
	return $result;
}

public function generate_menu($contract_type, $field_name, $selected_carrier_id = false, $css = NULL)
{
	$carriers = $this->PACKAGE->routing->carriers->get_open_carriers("",$contract_type);
	
	$text = "<select name='{$field_name}' class='{$css}'>";
	$text .= "<option value='none'>".lang('term_choose_carrier')."</option>";
	if(is_array($carriers)){
	foreach($carriers as $carrier)
	{
		$text .= "<option value='{$carrier['id']}' ";
		
		if($selected_carrier_id == $carrier['id'])
		{
			$text .= "selected='selected'";
		}
		
		$text .= ">{$carrier['username']}</option>";
	}
	}
	$text .= "</select>";
	
	return $text;
	
}

}
?>